package cn.bluethink.eguan.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgAcount;
import cn.bluethink.eguan.model.core.EgBag;
import cn.bluethink.eguan.model.core.EgCheckStatus;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgRole;
import cn.bluethink.eguan.model.core.EgUser;

/**
 * 用户实体模型
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.2.0
 * @brief 驿馆+（EGUAN）
 * @note 修订历史： 1、wanglei于2018/11/09修订格式
 */
@Table(name = "eg_user")
public class EgUserEntity implements Serializable {

    private static final long serialVersionUID = 9003453447054880416L;

    /**
     * 用户Id 主键
     */
    @Id
    @Column(name = "uid")
    private Long id;

    /**
     * 钉钉openId
     */
    @Column(name = "u_id")
    private String uid;

    private String name;

    private String avator;

    private Long bagid;

    private Long acount;

    private Integer role4;

    private Integer purview4;

    @Column(name = "check_status")
    private Integer checkStatus;

    private Integer skp;

    private Integer exp;

    @Column(name = "pos_otype")
    private Integer posOtype;

    @Column(name = "pos_oid")
    private Long posOid;

    private Date ctime;

    private Date utime;

    public EgUserEntity() {

    }

    /**
     * 创建操作
     * 
     * @param user
     * @param uid
     */
    public EgUserEntity(EgUser user, String uid) {
        this.id = user.getId();
        this.uid = uid;
        this.name = user.getName();
        this.avator = user.getAvatar();
        this.bagid = user.getBag().getId();
        this.acount = user.getAcount().getId();
        this.role4 = user.getRole() == null ? 0 : user.getRole().getRid();
        this.purview4 = user.getRole() == null ? 0 : user.getRole().getPurview();
        this.checkStatus = user.getCheckStatus() == null ? EgCheckStatus.STATUS_PENDING : user.getCheckStatus();
        this.skp = user.getSkp() == null ? 0 : user.getSkp();
        this.exp = user.getExp() == null ? 0 : user.getExp();
        this.posOtype = user.getPos() == null ? 0 : user.getPos().getType().getOtid();
        this.posOid = user.getPos() == null ? 0 : user.getPos().getId();
    }

    /**
     * 更新操作
     * 
     * @param user
     */
    public EgUserEntity(EgUser user) {
        this.id = user.getId();
        this.name = user.getName();
        this.avator = user.getAvatar();
        this.role4 = user.getRole() == null ? null : user.getRole().getRid();
        this.purview4 = user.getRole() == null ? null : user.getRole().getPurview();
        this.checkStatus = user.getCheckStatus() == null ? null : user.getCheckStatus();
        this.skp = user.getSkp() == null ? null : user.getSkp();
        this.exp = user.getExp() == null ? null : user.getExp();
        this.posOtype = user.getPos() == null ? null : user.getPos().getType().getOtid();
        this.posOid = user.getPos() == null ? null : user.getPos().getId();
    }

    /**
     * 更新用户位置信息
     * 
     * @param id
     * @param posOtype
     * @param posOid
     */
    public EgUserEntity(Long id, Integer posOtype, Long posOid) {
        this.id = id;
        this.posOtype = posOtype;
        this.posOid = posOid;
    }

    /**
     * 实体模型转业务模型
     * 
     * @return
     */
    public EgUser createUser() {
        EgUser user = new EgUser(id, name, avator);
        
        if(bagid != null && bagid > 0) {
            user.setBag(new EgBag(bagid, null));
        }
        
        if(acount != null && acount > 0) {
            user.setAcount(new EgAcount(acount, null, null));
        }
        
        user.setRole(new EgRole(role4, null, purview4));
        user.setCheckStatus(checkStatus);
        user.setExp(exp);
        user.setSkp(skp);
        
        if(posOid != null) {
            user.setPos(new EgObject(posOid, null, new EgOType(posOtype, null)));
        }
        
        user.setuTime(utime);
        return user;
    }

    /**
     * 实体模型转业务模型(用户ID,名称，头像)
     * 
     * @return
     */
    public EgUser createUserBasic() {
        return new EgUser(id, name, avator);
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAvator() {
        return avator;
    }

    public void setAvator(String avator) {
        this.avator = avator;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public Date getUtime() {
        return utime;
    }

    public void setUtime(Date utime) {
        this.utime = utime;
    }

    public Integer getCheckStatus() {
        return checkStatus;
    }

    public void setCheckStatus(Integer checkStatus) {
        this.checkStatus = checkStatus;
    }

    public Integer getSkp() {
        return skp;
    }

    public void setSkp(Integer skp) {
        this.skp = skp;
    }

    public Integer getExp() {
        return exp;
    }

    public void setExp(Integer exp) {
        this.exp = exp;
    }

    public Long getBagid() {
        return bagid;
    }

    public void setBagid(Long bagid) {
        this.bagid = bagid;
    }

    public Integer getRole4() {
        return role4;
    }

    public void setRole4(Integer role4) {
        this.role4 = role4;
    }

    public Integer getPurview4() {
        return purview4;
    }

    public void setPurview4(Integer purview4) {
        this.purview4 = purview4;
    }

    public Long getAcount() {
        return acount;
    }

    public void setAcount(Long acount) {
        this.acount = acount;
    }

    public Integer getPosOtype() {
        return posOtype;
    }

    public void setPosOtype(Integer posOtype) {
        this.posOtype = posOtype;
    }

    public Long getPosOid() {
        return posOid;
    }

    public void setPosOid(Long posOid) {
        this.posOid = posOid;
    }

}
